package com.zaimokuza.cn.entity.user;

import com.zaimokuza.cn.entity.auth.Resources;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author zaimokuza
 */
@ApiModel("用户")
@Data
public class SecurityUser implements UserDetails {

    @ApiModelProperty("用户ID")
    private String id;
    @ApiModelProperty("手机号")
    private Long phone;
    @ApiModelProperty("密码")
    private String password;
    @ApiModelProperty("权限列表")
    private ArrayList<GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getUsername() {
        return phone == null ? null : phone.toString();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
